# -*- coding: utf-8 -*-
"""
Created on Sun Oct 18 14:07:23 2020

create sensor manager use factory design pattern
工厂模式python实现
https://segmentfault.com/a/1190000013053013

@author: dalaska
"""


class sensor():
    """abstract sensor class, interface as product"""
    pass
        
class radar(sensor):
    """ a child class of sensor"""
    def __init__(self):
        print("radar")

class lidar(sensor):
    """child of sensor"""
    def __init__(self):
        print("lidar")    
    
class car():
    """ creator or facotry"""
    def __init__(self):
        print("manager")
    def create_sensor(self,type):
        if type == "radar":
            print("create radar")
            self.sensor = radar()
        elif type == "lidar":
            print("create lidar") 
            self.sensor = lidar()
        else:
            self.sensor = null
        return sensor

class L4_car(car):
    def __init__(self):
        self.create_sensor("lidar")

class L2_car(car):
    def __init__(self):
        self.create_sensor("radar")


if __name__ == "__main__":
    sens = sensor()
    rad = sensor()
    car = car()
    radar = car.create_sensor("radar")
    lidar = car.create_sensor("lidar")
    robotaxi = L4_car() 
    adascar = L2_car() 
    pass
